
$.ajax({
    url: "/Index/GetNavigation",
    type: "post",
    success: function (result) {
        var data = JSON.parse(result);
        var menuData = data.Data;
        if (data.Code == 200) {
            var menu = '<!-- 左侧菜单 --><div class="layui-side layui-bg-black left-menu-all ">';
            menu += '<div class="layui-side-scroll"><ul class="layui-nav layui-nav-tree left-menu" lay-filter="left-menu">';
            var menuData1 = [];//一级菜单
            var menuData2 = [];//二级菜单
            for (var i = 0; i < menuData.length; i++) {
                if (menuData[i].ParentId == 0) {
                    menuData1.push(menuData[i]);
                } else {
                    menuData2.push(menuData[i]);
                }
            }
            for (var i = 0; i < menuData1.length; i++) {
                menu += '<li class="layui-nav-item"><a href="javascript:;">' + menuData1[i].NavName + '</a>';
                menu += '<dl class="layui-nav-child">';
                for (var j = 0; j < menuData2.length; j++) {
                    if (menuData1[i].NavId == menuData2[j].ParentId) {
                        menu += '<dd><a href="' + menuData2[j].Url + '" data-id="' + menuData2[j].NavId + '">' + menuData2[j].NavName + '</a></dd>';
                    }
                }
                menu += '</dl></li>';
            }
            menu += '</ul></div></div>';
            $("#leftSlide").html(menu);

            layui.use(["element", "layer"], function () {
                var $ = layui.jquery,
                    element = layui.element,
                    layer = layui.layer;
                $(function () {
                    var l_o = $(".left-menu"),
                        tab = "top-tab",
                        l_m = "left-menu",
                        t_m = "top-menu";
                    var mainHeight = $(window).height() - 60;
                    l_o.on("click", "li", function () {
                        $(this).siblings().removeClass("layui-nav-itemed")
                    });

                    // 本地存储
                    l_o.find("a[data-id]").click(function () {
                        localStorage.dataId = $(this).attr('data-id')
                    });

                    $(".menu-flexible").click(function () {
                        $(".left-menu-all").toggle();
                        $(".layui-body,.layui-footer").css("left", ($(".left-menu-all").is(":hidden")) ? "0" : "200px")
                    });

                    // 判断是否有本地存储
                    if (localStorage.getItem('dataId')) {
                        var dataId = localStorage.getItem('dataId')
                        var getNowId = l_o.find("a[data-id=" + dataId + "]")
                        var getNowParent = $(getNowId).parent()

                        $(getNowParent).addClass('layui-this')
                        console.log($(getNowParent)[0]);
                        // 判断是否需要展开
                        if ($(getNowParent)[0].tagName == 'DD') {
                            $(getNowId).parents('.layui-nav-item').addClass('layui-nav-itemed');
                        }
                    }
                    // 目录
                    $(document).on("click", ".mulu,.masked", function () {
                        $('body').toggleClass('mulu-hide');
                    });

                    document.body.addEventListener('touchstart', function () { });

                });

                // 搜索
                $(document).on('click', '#search-btn', function () {
                    $('.search-res-mask').show();
                    $(this).parent().siblings('.search-fix').addClass('cur');

                })

                $(document).on('click', '#search-close', function () {
                    $('.search-res-mask').hide();
                    $(this).parents('.search-fix').removeClass('cur');

                })

                $(document).on('click', '.search-res-mask', function () {
                    $('#search-close').trigger('click');
                })

                // 移动端下拉
                $(document).on('click', '.layui-table .layui-table-first', function () {
                    if ($(window).width() > 992) {
                        return;
                    }
                    if ($(this).hasClass('cur')) {
                        $(this).siblings().hide();
                        $(this).removeClass('cur');
                    } else {
                        $($(this).siblings()).css('display', '-webkit-box');
                        $(this).addClass('cur');
                    }
                })


            });

        } else {
            console.log(data.Msg);
        }
    },
    error: function () {
        console.log("请求失败");
    }
});
